home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tk2.3 / dist / tkCanvBmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-24  |  17.1 KB  |  620 lines

  1. /* 
  2.  * tkCanvBmap.c --
  3.  *
  4.  *    This file implements bitmap items for canvas widgets.
  5.  *
  6.  * Copyright 1992 Regents of the University of California.
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /user6/ouster/wish/RCS/tkCanvBmap.c,v 1.4 92/08/24 09:24:11 ouster Exp $ SPRITE (Berkeley)";
  18. #endif
  19.  
  20. #include <stdio.h>
  21. #include <math.h>
  22. #include "tkInt.h"
  23. #include "tkCanvas.h"
  24.  
  25. /*
  26.  * The structure below defines the record for each rectangle/oval item.
  27.  */
  28.  
  29. typedef struct BitmapItem  {
  30.     Tk_Item header;        /* Generic stuff that's the same for all
  31.                  * types.  MUST BE FIRST IN STRUCTURE. */
  32.     double x, y;        /* Coordinates of positioning point for
  33.                  * bitmap. */
  34.     Tk_Anchor anchor;        /* Where to anchor bitmap relative to
  35.                  * (x,y). */
  36.     Pixmap bitmap;        /* Bitmap to display in window. */
  37.     XColor *fgColor;        /* Foreground color to use for bitmap. */
  38.     XColor *bgColor;        /* Background color to use for bitmap. */
  39.     GC gc;            /* Graphics context to use for drawing
  40.                  * bitmap on screen. */
  41. } BitmapItem;
  42.  
  43. /*
  44.  * Information used for parsing configuration specs:
  45.  */
  46.  
  47. static Tk_ConfigSpec configSpecs[] = {
  48.     {TK_CONFIG_ANCHOR, "-anchor", (char *) NULL, (char *) NULL,
  49.     "center", Tk_Offset(BitmapItem, anchor), TK_CONFIG_DONT_SET_DEFAULT},
  50.     {TK_CONFIG_COLOR, "-background", (char *) NULL, (char *) NULL,
  51.     (char *) NULL, Tk_Offset(BitmapItem, bgColor), TK_CONFIG_NULL_OK},
  52.     {TK_CONFIG_BITMAP, "-bitmap", (char *) NULL, (char *) NULL,
  53.     (char *) NULL, Tk_Offset(BitmapItem, bitmap), TK_CONFIG_NULL_OK},
  54.     {TK_CONFIG_COLOR, "-foreground", (char *) NULL, (char *) NULL,
  55.     "black", Tk_Offset(BitmapItem, fgColor), 0},
  56.     {TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL,
  57.     (char *) NULL, 0, TK_CONFIG_NULL_OK, &tkCanvasTagsOption},
  58.     {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
  59.     (char *) NULL, 0, 0}
  60. };
  61.  
  62. /*
  63.  * Prototypes for procedures defined in this file:
  64.  */
  65.  
  66. static int        BitmapCoords _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  67.                 Tk_Item *itemPtr, int argc, char **argv));
  68. static int        BitmapToArea _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  69.                 Tk_Item *itemPtr, double *rectPtr));
  70. static double        BitmapToPoint _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  71.                 Tk_Item *itemPtr, double *coordPtr));
  72. static void        ComputeBitmapBbox _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  73.                 BitmapItem *bmapPtr));
  74. static int        ConfigureBitmap _ANSI_ARGS_((
  75.                 Tk_Canvas *canvasPtr, Tk_Item *itemPtr, int argc,
  76.                 char **argv, int flags));
  77. static int        CreateBitmap _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  78.                 struct Tk_Item *itemPtr, int argc, char **argv));
  79. static void        DeleteBitmap _ANSI_ARGS_((Tk_Item *itemPtr));
  80. static void        DisplayBitmap _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  81.                 Tk_Item *itemPtr, Drawable dst));
  82. static void        ScaleBitmap _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  83.                 Tk_Item *itemPtr, double originX, double originY,
  84.                 double scaleX, double scaleY));
  85. static void        TranslateBitmap _ANSI_ARGS_((Tk_Canvas *canvasPtr,
  86.                 Tk_Item *itemPtr, double deltaX, double deltaY));
  87.  
  88. /*
  89.  * The structures below defines the rectangle and oval item types
  90.  * by means of procedures that can be invoked by generic item code.
  91.  */
  92.  
  93. Tk_ItemType TkBitmapType = {
  94.     "bitmap",                /* name */
  95.     sizeof(BitmapItem),            /* itemSize */
  96.     CreateBitmap,            /* createProc */
  97.     configSpecs,            /* configSpecs */
  98.     ConfigureBitmap,            /* configureProc */
  99.     BitmapCoords,            /* coordProc */
  100.     DeleteBitmap,            /* deleteProc */
  101.     DisplayBitmap,            /* displayProc */
  102.     0,                    /* alwaysRedraw */
  103.     BitmapToPoint,            /* pointProc */
  104.     BitmapToArea,            /* areaProc */
  105.     (Tk_ItemPostscriptProc *) NULL,    /* postscriptProc */
  106.     ScaleBitmap,            /* scaleProc */
  107.     TranslateBitmap,            /* translateProc */
  108.     (Tk_ItemIndexProc *) NULL,        /* indexProc */
  109.     (Tk_ItemCursorProc *) NULL,        /* cursorProc */
  110.     (Tk_ItemSelectionProc *) NULL,    /* selectionProc */
  111.     (Tk_ItemInsertProc *) NULL,        /* insertProc */
  112.     (Tk_ItemDCharsProc *) NULL,        /* dTextProc */
  113.     (Tk_ItemType *) NULL        /* nextPtr */
  114. };
  115.  
  116. /*
  117.  *--------------------------------------------------------------
  118.  *
  119.  * CreateBitmap --
  120.  *
  121.  *    This procedure is invoked to create a new bitmap
  122.  *    item in a canvas.
  123.  *
  124.  * Results:
  125.  *    A standard Tcl return value.  If an error occurred in
  126.  *    creating the item, then an error message is left in
  127.  *    canvasPtr->interp->result;  in this case itemPtr is
  128.  *    left uninitialized, so it can be safely freed by the
  129.  *    caller.
  130.  *
  131.  * Side effects:
  132.  *    A new bitmap item is created.
  133.  *
  134.  *--------------------------------------------------------------
  135.  */
  136.  
  137. static int
  138. CreateBitmap(canvasPtr, itemPtr, argc, argv)
  139.     register Tk_Canvas *canvasPtr;    /* Canvas to hold new item. */
  140.     Tk_Item *itemPtr;            /* Record to hold new item;  header
  141.                      * has been initialized by caller. */
  142.     int argc;                /* Number of arguments in argv. */
  143.     char **argv;            /* Arguments describing rectangle. */
  144. {
  145.     register BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
  146.  
  147.     if (argc < 2) {
  148.     Tcl_AppendResult(canvasPtr->interp, "wrong # args:  should be \"",
  149.         Tk_PathName(canvasPtr->tkwin), "\" create ",
  150.         itemPtr->typePtr->name, " x y ?options?",
  151.         (char *) NULL);
  152.     return TCL_ERROR;
  153.     }
  154.  
  155.     /*
  156.      * Initialize item's record.
  157.      */
  158.  
  159.     bmapPtr->anchor = TK_ANCHOR_CENTER;
  160.     bmapPtr->bitmap = None;
  161.     bmapPtr->fgColor = NULL;
  162.     bmapPtr->bgColor = NULL;
  163.     bmapPtr->gc = None;
  164.  
  165.     /*
  166.      * Process the arguments to fill in the item record.
  167.      */
  168.  
  169.     if ((TkGetCanvasCoord(canvasPtr, argv[0], &bmapPtr->x) != TCL_OK)
  170.         || (TkGetCanvasCoord(canvasPtr, argv[1],
  171.         &bmapPtr->y) != TCL_OK)) {
  172.     return TCL_ERROR;
  173.     }
  174.  
  175.     if (ConfigureBitmap(canvasPtr, itemPtr, argc-2, argv+2, 0) != TCL_OK) {
  176.     DeleteBitmap(itemPtr);
  177.     return TCL_ERROR;
  178.     }
  179.     return TCL_OK;
  180. }
  181.  
  182. /*
  183.  *--------------------------------------------------------------
  184.  *
  185.  * BitmapCoords --
  186.  *
  187.  *    This procedure is invoked to process the "coords" widget
  188.  *    command on bitmap items.  See the user documentation for
  189.  *    details on what it does.
  190.  *
  191.  * Results:
  192.  *    Returns TCL_OK or TCL_ERROR, and sets canvasPtr->interp->result.
  193.  *
  194.  * Side effects:
  195.  *    The coordinates for the given item may be changed.
  196.  *
  197.  *--------------------------------------------------------------
  198.  */
  199.  
  200. static int
  201. BitmapCoords(canvasPtr, itemPtr, argc, argv)
  202.     register Tk_Canvas *canvasPtr;    /* Canvas containing item. */
  203.     Tk_Item *itemPtr;            /* Item whose coordinates are to be
  204.                      * read or modified. */
  205.     int argc;                /* Number of coordinates supplied in
  206.                      * argv. */
  207.     char **argv;            /* Array of coordinates: x1, y1,
  208.                      * x2, y2, ... */
  209. {
  210.     register BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
  211.  
  212.     if (argc == 0) {
  213.     sprintf(canvasPtr->interp->result, "%g %g", bmapPtr->x, bmapPtr->y);
  214.     } else if (argc == 2) {
  215.     if ((TkGetCanvasCoord(canvasPtr, argv[0], &bmapPtr->x) != TCL_OK)
  216.         || (TkGetCanvasCoord(canvasPtr, argv[1],
  217.             &bmapPtr->y) != TCL_OK)) {
  218.         return TCL_ERROR;
  219.     }
  220.     ComputeBitmapBbox(canvasPtr, bmapPtr);
  221.     } else {
  222.     sprintf(canvasPtr->interp->result,
  223.         "wrong # coordinates:  expected 0 or 2, got %d",
  224.         argc);
  225.     return TCL_ERROR;
  226.     }
  227.     return TCL_OK;
  228. }
  229.  
  230. /*
  231.  *--------------------------------------------------------------
  232.  *
  233.  * ConfigureBitmap --
  234.  *
  235.  *    This procedure is invoked to configure various aspects
  236.  *    of a bitmap item, such as its anchor position.
  237.  *
  238.  * Results:
  239.  *    A standard Tcl result code.  If an error occurs, then
  240.  *    an error message is left in canvasPtr->interp->result.
  241.  *
  242.  * Side effects:
  243.  *    Configuration information may be set for itemPtr.
  244.  *
  245.  *--------------------------------------------------------------
  246.  */
  247.  
  248. static int
  249. ConfigureBitmap(canvasPtr, itemPtr, argc, argv, flags)
  250.     Tk_Canvas *canvasPtr;    /* Canvas containing itemPtr. */
  251.     Tk_Item *itemPtr;        /* Bitmap item to reconfigure. */
  252.     int argc;            /* Number of elements in argv.  */
  253.     char **argv;        /* Arguments describing things to configure. */
  254.     int flags;            /* Flags to pass to Tk_ConfigureWidget. */
  255. {
  256.     register BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
  257.     XGCValues gcValues;
  258.     GC newGC;
  259.  
  260.     if (Tk_ConfigureWidget(canvasPtr->interp, canvasPtr->tkwin,
  261.         configSpecs, argc, argv, (char *) bmapPtr, flags) != TCL_OK) {
  262.     return TCL_ERROR;
  263.     }
  264.  
  265.     /*
  266.      * A few of the options require additional processing, such as those
  267.      * that determine the graphics context.
  268.      */
  269.  
  270.     gcValues.foreground = bmapPtr->fgColor->pixel;
  271.     if (bmapPtr->bgColor != NULL) {
  272.     gcValues.background = bmapPtr->bgColor->pixel;
  273.     } else {
  274.     gcValues.background = canvasPtr->bgColor->pixel;
  275.     }
  276.     newGC = Tk_GetGC(canvasPtr->tkwin, GCForeground|GCBackground, &gcValues);
  277.     if (bmapPtr->gc != None) {
  278.     Tk_FreeGC(bmapPtr->gc);
  279.     }
  280.     bmapPtr->gc = newGC;
  281.  
  282.     ComputeBitmapBbox(canvasPtr, bmapPtr);
  283.  
  284.     return TCL_OK;
  285. }
  286.  
  287. /*
  288.  *--------------------------------------------------------------
  289.  *
  290.  * DeleteBitmap --
  291.  *
  292.  *    This procedure is called to clean up the data structure
  293.  *    associated with a bitmap item.
  294.  *
  295.  * Results:
  296.  *    None.
  297.  *
  298.  * Side effects:
  299.  *    Resources associated with itemPtr are released.
  300.  *
  301.  *--------------------------------------------------------------
  302.  */
  303.  
  304. static void
  305. DeleteBitmap(itemPtr)
  306.     Tk_Item *itemPtr;            /* Item that is being deleted. */
  307. {
  308.     register BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
  309.  
  310.     if (bmapPtr->bitmap != None) {
  311.     Tk_FreeBitmap(bmapPtr->bitmap);
  312.     }
  313.     if (bmapPtr->fgColor != NULL) {
  314.     Tk_FreeColor(bmapPtr->fgColor);
  315.     }
  316.     if (bmapPtr->bgColor != NULL) {
  317.     Tk_FreeColor(bmapPtr->bgColor);
  318.     }
  319.     if (bmapPtr->gc != NULL) {
  320.     Tk_FreeGC(bmapPtr->gc);
  321.     }
  322. }
  323.  
  324. /*
  325.  *--------------------------------------------------------------
  326.  *
  327.  * ComputeBitmapBbox --
  328.  *
  329.  *    This procedure is invoked to compute the bounding box of
  330.  *    all the pixels that may be drawn as part of a bitmap item.
  331.  *    This procedure is where the child bitmap's placement is
  332.  *    computed.
  333.  *
  334.  * Results:
  335.  *    None.
  336.  *
  337.  * Side effects:
  338.  *    The fields x1, y1, x2, and y2 are updated in the header
  339.  *    for itemPtr.
  340.  *
  341.  *--------------------------------------------------------------
  342.  */
  343.  
  344.     /* ARGSUSED */
  345. static void
  346. ComputeBitmapBbox(canvasPtr, bmapPtr)
  347.     Tk_Canvas *canvasPtr;        /* Canvas that contains item. */
  348.     register BitmapItem *bmapPtr;    /* Item whose bbox is to be
  349.                      * recomputed. */
  350. {
  351.     unsigned int width, height;
  352.     int x, y;
  353.  
  354.     x = bmapPtr->x + 0.5;
  355.     y = bmapPtr->y + 0.5;
  356.  
  357.     if (bmapPtr->bitmap == None) {
  358.     bmapPtr->header.x1 = bmapPtr->header.x2 = x;
  359.     bmapPtr->header.y1 = bmapPtr->header.y2 = y;
  360.     return;
  361.     }
  362.  
  363.     /*
  364.      * Compute location and size of bitmap, using anchor information.
  365.      */
  366.  
  367.     Tk_SizeOfBitmap(bmapPtr->bitmap, &width, &height);
  368.     switch (bmapPtr->anchor) {
  369.     case TK_ANCHOR_N:
  370.         x -= width/2;
  371.         break;
  372.     case TK_ANCHOR_NE:
  373.         x -= width;
  374.         break;
  375.     case TK_ANCHOR_E:
  376.         x -= width;
  377.         y -= height/2;
  378.         break;
  379.     case TK_ANCHOR_SE:
  380.         x -= width;
  381.         y -= height;
  382.         break;
  383.     case TK_ANCHOR_S:
  384.         x -= width/2;
  385.         y -= height;
  386.         break;
  387.     case TK_ANCHOR_SW:
  388.         y -= height;
  389.         break;
  390.     case TK_ANCHOR_W:
  391.         y -= height/2;
  392.         break;
  393.     case TK_ANCHOR_NW:
  394.         break;
  395.     case TK_ANCHOR_CENTER:
  396.         x -= width/2;
  397.         y -= height/2;
  398.         break;
  399.     }
  400.  
  401.     /*
  402.      * Store the information in the item header.
  403.      */
  404.  
  405.     bmapPtr->header.x1 = x;
  406.     bmapPtr->header.y1 = y;
  407.     bmapPtr->header.x2 = x + width;
  408.     bmapPtr->header.y2 = y + height;
  409. }
  410.  
  411. /*
  412.  *--------------------------------------------------------------
  413.  *
  414.  * DisplayBitmap --
  415.  *
  416.  *    This procedure is invoked to draw a bitmap item in a given
  417.  *    drawable.
  418.  *
  419.  * Results:
  420.  *    None.
  421.  *
  422.  * Side effects:
  423.  *    ItemPtr is drawn in drawable using the transformation
  424.  *    information in canvasPtr.
  425.  *
  426.  *--------------------------------------------------------------
  427.  */
  428.  
  429. static void
  430. DisplayBitmap(canvasPtr, itemPtr, drawable)
  431.     register Tk_Canvas *canvasPtr;    /* Canvas that contains item. */
  432.     Tk_Item *itemPtr;            /* Item to be displayed. */
  433.     Drawable drawable;            /* Pixmap or window in which to draw
  434.                      * item. */
  435. {
  436.     register BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
  437.  
  438.     if (bmapPtr->bitmap != None) {
  439.     XCopyPlane(Tk_Display(canvasPtr->tkwin), bmapPtr->bitmap, drawable,
  440.         bmapPtr->gc, 0, 0,
  441.         (unsigned int) bmapPtr->header.x2 - bmapPtr->header.x1,
  442.         (unsigned int) bmapPtr->header.y2 - bmapPtr->header.y1,
  443.         bmapPtr->header.x1 - canvasPtr->drawableXOrigin,
  444.         bmapPtr->header.y1 - canvasPtr->drawableYOrigin, 1);
  445.     }
  446. }
  447.  
  448. /*
  449.  *--------------------------------------------------------------
  450.  *
  451.  * BitmapToPoint --
  452.  *
  453.  *    Computes the distance from a given point to a given
  454.  *    rectangle, in canvas units.
  455.  *
  456.  * Results:
  457.  *    The return value is 0 if the point whose x and y coordinates
  458.  *    are coordPtr[0] and coordPtr[1] is inside the bitmap.  If the
  459.  *    point isn't inside the bitmap then the return value is the
  460.  *    distance from the point to the bitmap.
  461.  *
  462.  * Side effects:
  463.  *    None.
  464.  *
  465.  *--------------------------------------------------------------
  466.  */
  467.  
  468.     /* ARGSUSED */
  469. static double
  470. BitmapToPoint(canvasPtr, itemPtr, coordPtr)
  471.     Tk_Canvas *canvasPtr;    /* Canvas containing item. */
  472.     Tk_Item *itemPtr;        /* Item to check against point. */
  473.     double *coordPtr;        /* Pointer to x and y coordinates. */
  474. {
  475.     register BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
  476.     double x1, x2, y1, y2, xDiff, yDiff;
  477.  
  478.     x1 = bmapPtr->header.x1;
  479.     y1 = bmapPtr->header.y1;
  480.     x2 = bmapPtr->header.x2;
  481.     y2 = bmapPtr->header.y2;
  482.  
  483.     /*
  484.      * Point is outside rectangle.
  485.      */
  486.  
  487.     if (coordPtr[0] < x1) {
  488.     xDiff = x1 - coordPtr[0];
  489.     } else if (coordPtr[0] > x2)  {
  490.     xDiff = coordPtr[0] - x2;
  491.     } else {
  492.     xDiff = 0;
  493.     }
  494.  
  495.     if (coordPtr[1] < y1) {
  496.     yDiff = y1 - coordPtr[1];
  497.     } else if (coordPtr[1] > y2)  {
  498.     yDiff = coordPtr[1] - y2;
  499.     } else {
  500.     yDiff = 0;
  501.     }
  502.  
  503.     return hypot(xDiff, yDiff);
  504. }
  505.  
  506. /*
  507.  *--------------------------------------------------------------
  508.  *
  509.  * BitmapToArea --
  510.  *
  511.  *    This procedure is called to determine whether an item
  512.  *    lies entirely inside, entirely outside, or overlapping
  513.  *    a given rectangle.
  514.  *
  515.  * Results:
  516.  *    -1 is returned if the item is entirely outside the area
  517.  *    given by rectPtr, 0 if it overlaps, and 1 if it is entirely
  518.  *    inside the given area.
  519.  *
  520.  * Side effects:
  521.  *    None.
  522.  *
  523.  *--------------------------------------------------------------
  524.  */
  525.  
  526.     /* ARGSUSED */
  527. static int
  528. BitmapToArea(canvasPtr, itemPtr, rectPtr)
  529.     Tk_Canvas *canvasPtr;    /* Canvas containing item. */
  530.     Tk_Item *itemPtr;        /* Item to check against rectangle. */
  531.     double *rectPtr;        /* Pointer to array of four coordinates
  532.                  * (x1, y1, x2, y2) describing rectangular
  533.                  * area.  */
  534. {
  535.     register BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
  536.  
  537.     if ((rectPtr[2] <= bmapPtr->header.x1)
  538.         || (rectPtr[0] >= bmapPtr->header.x2)
  539.         || (rectPtr[3] <= bmapPtr->header.y1)
  540.         || (rectPtr[1] >= bmapPtr->header.y2)) {
  541.     return -1;
  542.     }
  543.     if ((rectPtr[0] <= bmapPtr->header.x1)
  544.         && (rectPtr[1] <= bmapPtr->header.y1)
  545.         && (rectPtr[2] >= bmapPtr->header.x2)
  546.         && (rectPtr[3] >= bmapPtr->header.y2)) {
  547.     return 1;
  548.     }
  549.     return 0;
  550. }
  551.  
  552. /*
  553.  *--------------------------------------------------------------
  554.  *
  555.  * ScaleBitmap --
  556.  *
  557.  *    This procedure is invoked to rescale a rectangle or oval
  558.  *    item.
  559.  *
  560.  * Results:
  561.  *    None.
  562.  *
  563.  * Side effects:
  564.  *    The rectangle or oval referred to by itemPtr is rescaled
  565.  *    so that the following transformation is applied to all
  566.  *    point coordinates:
  567.  *        x' = originX + scaleX*(x-originX)
  568.  *        y' = originY + scaleY*(y-originY)
  569.  *
  570.  *--------------------------------------------------------------
  571.  */
  572.  
  573. static void
  574. ScaleBitmap(canvasPtr, itemPtr, originX, originY, scaleX, scaleY)
  575.     Tk_Canvas *canvasPtr;        /* Canvas containing rectangle. */
  576.     Tk_Item *itemPtr;            /* Rectangle to be scaled. */
  577.     double originX, originY;        /* Origin about which to scale rect. */
  578.     double scaleX;            /* Amount to scale in X direction. */
  579.     double scaleY;            /* Amount to scale in Y direction. */
  580. {
  581.     register BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
  582.  
  583.     bmapPtr->x = originX + scaleX*(bmapPtr->x - originX);
  584.     bmapPtr->y = originY + scaleY*(bmapPtr->y - originY);
  585.     ComputeBitmapBbox(canvasPtr, bmapPtr);
  586. }
  587.  
  588. /*
  589.  *--------------------------------------------------------------
  590.  *
  591.  * TranslateBitmap --
  592.  *
  593.  *    This procedure is called to move a rectangle or oval by a
  594.  *    given amount.
  595.  *
  596.  * Results:
  597.  *    None.
  598.  *
  599.  * Side effects:
  600.  *    The position of the rectangle or oval is offset by
  601.  *    (xDelta, yDelta), and the bounding box is updated in the
  602.  *    generic part of the item structure.
  603.  *
  604.  *--------------------------------------------------------------
  605.  */
  606.  
  607. static void
  608. TranslateBitmap(canvasPtr, itemPtr, deltaX, deltaY)
  609.     Tk_Canvas *canvasPtr;        /* Canvas containing item. */
  610.     Tk_Item *itemPtr;            /* Item that is being moved. */
  611.     double deltaX, deltaY;        /* Amount by which item is to be
  612.                      * moved. */
  613. {
  614.     register BitmapItem *bmapPtr = (BitmapItem *) itemPtr;
  615.  
  616.     bmapPtr->x += deltaX;
  617.     bmapPtr->y += deltaY;
  618.     ComputeBitmapBbox(canvasPtr, bmapPtr);
  619. }
  620.